'''
计数排序，适合数据范围固定，可用map或array实现
'''
import random
from collections import Counter


def count_sort(nums):
    if not nums: return
    counter = Counter(nums)
    max_v = max(nums)
    min_v = min(nums)
    k = 0
    for i in range(min_v, max_v + 1):
        for _ in range(counter[i]):
            nums[k] = i
            k += 1


nums = [random.randint(-100, 100) for _ in range(1000000)]
nums1 = nums[:]
nums2 = nums[:]
count_sort(nums1)
nums2.sort()
print(nums)
print(nums2)
print(nums1 == nums2)
